package com.cc.config;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.Filter;

/**
 * @author CC
 * @version 1.0
 * @description: TODO
 * @date 2025/6/16 11:22
 */
public class WebMVCConfig extends AbstractAnnotationConfigDispatcherServletInitializer {
    @Override
    protected Class<?>[] getRootConfigClasses() {
        //  根容器配置 spring 容器
        return new Class[]{SpringConfig.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        // 添加 DispatcherServlet 配置 springMVC 容器
        return new Class[]{SpringMVCConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
        // 添加 DispatcherServlet 映射
        return new String[]{"/"};
    }

    @Override
    protected Filter[] getServletFilters() {
        // 添加过滤器 字符集  post 乱码问题
        CharacterEncodingFilter encodingFilter  = new CharacterEncodingFilter();
        encodingFilter.setEncoding("UTF-8");
        return new Filter[]{encodingFilter};
    }
}

